package com.qf.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qf.pojo.DtsTopic;
import com.qf.service.TopicService;
import com.qf.util.ResponseUtil;
import org.omg.CORBA.INTERNAL;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * projectName: shop-manage
 *
 * @author: 元
 * time: 2021/9/15 0015 9:23
 * description:
 */
@RestController
@CrossOrigin("*")
@RequestMapping("topic")
public class TopicController {

    @Autowired
    private TopicService topicService;

    //专题列表展示
    @RequestMapping("list")
    public Object list(Integer page,Integer limit,String title,String subtitle,String sort,String order){
        IPage<DtsTopic> topicIPage = topicService.selectByPage(page,limit,title,subtitle,sort,order);
        Map<String,Object> data = new HashMap<>();
        data.put("total",topicIPage.getTotal());
        data.put("items",topicIPage.getRecords());
        return ResponseUtil.ok(data);
    }


    //添加专题
    @RequestMapping("create")
    public Object create(@RequestBody DtsTopic dtsTopic){
       dtsTopic = topicService.addTopic(dtsTopic);
        return ResponseUtil.ok(dtsTopic);
    }


    //修改专题信息
    @RequestMapping("update")
    public Object update(@RequestBody DtsTopic dtsTopic){
        int rows = topicService.updateTopic(dtsTopic);
        return ResponseUtil.ok(dtsTopic);
    }

    //删除专题
    @RequestMapping("delete")
    public Object delete(Integer id){
        int rows = topicService.removeById(id);
        return ResponseUtil.ok();

    }








}
